package main

import "fmt"

func permute(nums []int) [][]int {
	var res [][]int
	var list []int
	used := make(map[int]bool)

	var helper func()
	helper = func() {
		if len(list) == len(nums) {
			tmp := make([]int, len(nums))
			copy(tmp, list)
			res = append(res, tmp)
			return
		}

		for i := 0; i < len(nums); i++ {
			if !used[i] {
				used[i] = true
				list = append(list, list[i])
				helper()
				list = list[:len(list)-1]
				used[i] = false
			}
		}
	}
	helper()
	return res
}

func main() {
	fmt.Println(permute([]int{1, 2, 3}))
}
